package com.cat.dataStructure;

import java.util.PriorityQueue;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-operations-to-halve-array-sum/description/
 * @create 2025/10/6 16:22
 * @since JDK17
 */

public class Solution98 {
    public int halveArray(int[] nums) {
        double sum = 0;
        PriorityQueue<Double> heap = new PriorityQueue<>((a, b) -> Double.compare(b, a));
        for (int num : nums) {
            sum += num;
            heap.add(((double) num));
        }
        int ans = 0;
        sum /= 2;
        while (sum > 0) {
            var x = heap.poll() / 2;
            sum -= x;
            heap.add(x);
            ans++;
        }
        return ans;
    }
}
